package com.m1905.lib.download.request;

import static android.text.format.DateUtils.SECOND_IN_MILLIS;

import com.m1905.lib.download.listener.RequestListener;


/**
 * @author wanghao
 * @date 2023/9/20.
 * @des
 */
public abstract class BaseDownloadRequest {

    protected static final int MAX_REDIRECTS = 5;
    protected static final int DEFAULT_TIMEOUT = (int) (20 * SECOND_IN_MILLIS);
    protected static final int HTTP_TEMP_REDIRECT = 307;
    protected static final int HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416;

    public static final int STATUS_CANNOT_RESUME = 4001;
    public static final int STATUS_HTTP_DATA_ERROR = 4002;
    public static final int STATUS_FILE_ERROR = 4003;
    public static final int STATUS_URL_ERROR = 4004;
    public static final int STATUS_TOO_MANY_REDIRECTS = 4007;
    public static final int STATUS_NETWORK_ERROR = 4008;
    public static final int STATUS_TIMEOUT_ERROR = 4009;
    public static final int STATUS_RESPONSE_CODE_ERROR = 4010;
    public static final int BUFFER_SIZE = 65536;

    protected RequestListener mListener;
    protected String mFilePath;
    protected String urlStr;
    protected boolean isResume;

    protected long mTotalBytes;
    protected long mLastTotalSize;
    protected long mCurrentBytes;


    public void download(String filePath, String url, long lastTotalSize, boolean isResume, RequestListener listener) {
        this.mFilePath = filePath;
        this.urlStr = url;
        this.mLastTotalSize = lastTotalSize;
        this.isResume = isResume;
        this.mListener = listener;
        startDownload();
    }

    public abstract void startDownload();


}
